import { fetchList, delObj } from "@/views/wy-lessor/landlord/api/lessor";
import clientExport from "@/views/wy-lessor/landlord/components/client-export.vue";
// hxf-0805-引入校验字段名混合
import EditBase from "@/assets/vue-mixin/EditBase";
import { getDict } from "~/utils";
// hxf-0806-引入loading混合
import BaseLoad from "@/assets/vue-mixin/BaseLoad";
import pager from "@/assets/vue-mixin/pager";
import { mapState } from "vuex";

export default {
    name: "new-reimbursement",
    mixins: [pager, EditBase, BaseLoad],
    components: {
        clientExport
    },
    computed: mapState({
        //客户类型
        lessee_type: state => {
            let data =
                state.dict.find(item => item.type === "lessee_type") || {};
            //let list = data.children || []
            return data.children || [];
        }
    }),
    mounted() {
        //获取数据字段的值
        this.totalSearchData[0].children = this.lessee_type;
        // console.log(this.approve_template);
    },
    data() {
        return {
            tableData: [],
            lesseeTypeList: [],
            searchForm: {},
            totalSearchData: [
                {
                    label: "出租方类型",
                    value: "type",
                    type: "select",
                    model: "type",
                    children: []
                }
            ],
            searchDataFrom: {},
            timeData: [],
            placeholder: "请输入出租方名称"
        };
    },

    methods: {
        lessee_type_list(row, column, cellValue) {
            let obj = this.lessee_type.find(p => p.value == cellValue);
            if (obj) {
                return obj.label;
            }
            return "";
        },
        getListData() {
            fetchList(Object.assign({}, this.pageParams, this.searchForm))
                .then(response => {
                    this.setListData(response.data);
                })
                .catch(() => {
                    console.log("catch");
                });
        },
        searchByKey(val) {
            // console.log('searchByKey', this.searchDataFrom);
            //获取输入的值
            if (val) {
                this.searchForm.lessorName = val;
            } else {
                delete this.searchForm.lessorName;
            }
            if (this.searchDataFrom.type) {
                let sum = [];
                this.searchDataFrom.types.map(item => {
                    sum.push(item.value);
                });
                this.searchForm.lessorTypes = sum;
            }
            this.resetList();
        },
        //qh+：点击编辑跳转到新的页面
        toEdit(row) {
            this.$router.push({
                path: "/wy-lessor/lessor-manage/edit?id=" + row.lessorId
            });
        },
        //qh+:点击查看跳转到查看页面
        toAdd() {
            this.$router.push({ path: "/wy-lessor/lessor-manage/add" });
        },
        toImport() {
            this.$router.push({ path: "/wy-lessor/lessor-manage/import" });
        },
        //qh+:点击名称跳转
        toPerson(row) {
            //点击列表页名称跳转
            this.$router.push({
                path: "/wy-lessor/lessor-manage/look?id=" + row.lessorId
            });
        },
        //qh+:显示导出弹出框
        toExport() {
            this.$refs.clientExport.show();
        },

        //qh+：重置
        searchReset() {
            // console.log("====searchReset")
            //清空选中的数据
            this.searchForm = {};
            //重新查询
            this.resetList();
        },
        rowDel(row) {
            //取出数据，由于字段名不一样，需要创建一个对应实体类表字段名的对象作为参数
            //也可以直接obj=row
            var obj = {};
            //obj.clientLesseeId=row.clientLesseeId;
            this.$confirm("此操作将永久删除该记录, 是否继续?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(() => {
                    //删除
                    delObj(row.lessorId).then(response => {
                        this.resetList();
                    });

                    this.$message({
                        type: "success",
                        message: "删除成功!"
                    });
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消删除"
                    });
                });
        }
    }
};
